package com.bookstore.web.servlet;

import com.bookstore.exception.UserException;
import com.bookstore.service.UserService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/activate")
public class ActivateServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest reqrest, HttpServletResponse response) throws ServletException, IOException {
        response.setHeader("content-type","text/html;charset=utf-8");
        //1.获取参数
        String ActivateCode=reqrest.getParameter("ActivateCode");
        //2.Activate
        UserService us = new UserService();
        try {
            us.activeUser(ActivateCode);
            response.getWriter().write("Activate Succeed");
        } catch (UserException e) {
            e.printStackTrace();
            response.getWriter().write(e.getMessage());

        }

    }
}
